const app = getApp();
const douban = app.globalData.doubanUrl;
import utils from "../../utils/utils";
const http = utils.http;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    "in_theaters": {},
    "coming_soon": {},
    "top250": {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var count = "?start==0&count=3";
    var inTheatersUrl = douban + "in_theaters" + count;
    var comingSoon = douban + "coming_soon" + count;
    var top250 = douban + "top250" + count;
    http(inTheatersUrl, this.handleData, "in_theaters");
    http(comingSoon, this.handleData, "coming_soon");
    http(top250, this.handleData, "top250");
  },
  handleData(res, type) {
    var title = res.data.title;
    var subjects = res.data.subjects;
    var movies = [];
    subjects.forEach(ele => {
      var title = ele.title;
      var id = ele.id;
      var temp = {
        title,
        id
      };
      movies.push(temp);
    })
    var readyData = {};
    readyData[type] = {
      movies,
      title,
      type
    };
    this.setData(readyData);
   
  },
  more(event) {
    var type = event.currentTarget.dataset.type;
    /* console.log(type); */
    var title = event.currentTarget.dataset.title;
   /*  console.log(title); */
    wx.navigateTo({
      url: 'movies-list/movies-list?type=' + type + "&title=" + title
    });
  }
})